﻿using DayuCode.Designer.Entity;
using DayuCode.Designer.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DayuCode.Designer.Service
{
    public class ProjectUserHandler
    {
        private static string getBaseUrl(string methodName)
        {
            return AppInstance.ApiServer + "api/base/dayucode_projectUserHandler/" + methodName;
        }

		public static IList<ProjectUser> getProjectUsers(long projectId)
		{
			IList<ProjectUser> obj = QHttpClient.Post<List<ProjectUser>>(getBaseUrl("getProjectUsers"), new { projectId = projectId });
			return obj;
		}

		public static ProjectUser getProjectUser(long id)
		{
			ProjectUser obj = QHttpClient.Post<ProjectUser>(getBaseUrl("getProjectUser"), new { id = id });
			return obj;
		}

		public static void deleteProjectUser(long id)
		{
			QHttpClient.Execute(getBaseUrl("deleteProjectUser"), new { id = id });
		}

		public static ProjectUser addSuperAdmin(string userId)
		{
			ProjectUser obj = QHttpClient.Post<ProjectUser>(getBaseUrl("addSuperAdmin"), new { userId = userId });
			return obj;
		}

		public static ProjectUser addProjectUser(string userId, long projectId, bool isProjectAdmin)
		{
			ProjectUser obj = QHttpClient.Post<ProjectUser>(getBaseUrl("addProjectUser"), new { userId = userId, projectId = projectId, isProjectAdmin = isProjectAdmin });
			return obj;
		}

		public static ProjectUser changeProjectAdmin(long projectUserId, bool isProjectAdmin)
		{
			ProjectUser obj = QHttpClient.Post<ProjectUser>(getBaseUrl("changeProjectAdmin"), new { projectUserId = projectUserId, isProjectAdmin = isProjectAdmin });
			return obj;
		}
	}
}
